<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            padding-bottom: 800px;
        }
        .box{
            width: 600px;
            height: 600px;
            border: 1px solid #666;
        }
        .menu{
            display: flex;
            flex-flow: column wrap;
            box-shadow: 0 0 6px #666;
            width: 200px;
            border-radius: 8px;
            position: fixed;
            top: 0px;
            left: 0px;
            background-color: white;
        }
        .menu span{
            height: 30px;
            line-height: 30px;
            font-size: 16px;
            padding: 8px 20px;
            cursor: pointer;
        }
        .menu span:hover{
            background-color: #dedede;
        }
        .map{
            position: fixed;
            top: 0px;
            left: 0px;
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <div id="app" >

        <div class="map"  @contextmenu="isShowMenu=false">
            <!-- map 元素是一个临时的解决方案，实际开发的方法，在vue讲解完成生命周期钩子函数后，进行重新说明 -->

            <div class="box" @contextmenu.prevent.stop="printMsg($event)" @click="isShowMenu=false"></div>
    
            <div class="menu" :style=" isShowMenu?`top:${top}px;left:${left}px;`:'display: none;' ">
                <span>详情</span>
                <span>修改</span>
                <span>删除</span>
            </div>

        </div>


    </div>
    <script type="module"> 
        import { createApp } from "../assets/vue3/vue.esm-browser.js";
        createApp({
            data(){
                return {
                    isShowMenu:false,
                    top:0,
                    left:0
                }
            },
            methods:{
                printMsg(e){
                    console.log("右键菜单事件:",e)
                    this.isShowMenu = true;
                    this.top = e.y;
                    this.left = e.x;
                }
            }
        }).mount("#app")
    </script>
</body>
</html>